
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>防抖节流 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Landen">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-toggle-chapters/toggle.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-image-captions/image-captions.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="同步异步.html" />
    
    
    <link rel="prev" href="图片预览.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../01html/html简介.html">
            
                <a href="../01html/html简介.html">
            
                    
                    HTML
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../01html/01html.html">
            
                <a href="../01html/01html.html">
            
                    
                    a链接、图片
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../01html/02html.html">
            
                <a href="../01html/02html.html">
            
                    
                    列表、表格、表单
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../01html/h5新增.html">
            
                <a href="../01html/h5新增.html">
            
                    
                    h5新增
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../02css/css简介.html">
            
                <a href="../02css/css简介.html">
            
                    
                    CSS
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../02css/居中、省略、清浮.html">
            
                <a href="../02css/居中、省略、清浮.html">
            
                    
                    居中、省略、清浮
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../02css/浮动和定位.html">
            
                <a href="../02css/浮动和定位.html">
            
                    
                    浮动和定位
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../02css/变换、过渡、动画.html">
            
                <a href="../02css/变换、过渡、动画.html">
            
                    
                    变换、过渡、动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../02css/sass和rem.html">
            
                <a href="../02css/sass和rem.html">
            
                    
                    sass和rem
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../02css/flex、media、栅格化.html">
            
                <a href="../02css/flex、media、栅格化.html">
            
                    
                    flex、media、栅格化
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="js简介.html">
            
                <a href="js简介.html">
            
                    
                    JavaScript
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="数据类型.html">
            
                <a href="数据类型.html">
            
                    
                    数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="字符串.html">
            
                <a href="字符串.html">
            
                    
                    字符串
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="数组.html">
            
                <a href="数组.html">
            
                    
                    数组
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="回流和重绘.html">
            
                <a href="回流和重绘.html">
            
                    
                    回流和重绘
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="浏览器的渲染过程.html">
            
                <a href="浏览器的渲染过程.html">
            
                    
                    浏览器的渲染过程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="十大排序算法.html">
            
                <a href="十大排序算法.html">
            
                    
                    十大排序算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="对象的构建.html">
            
                <a href="对象的构建.html">
            
                    
                    对象的构建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8" data-path="this.html">
            
                <a href="this.html">
            
                    
                    this
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.9" data-path="bind&call&apply.html">
            
                <a href="bind&call&apply.html">
            
                    
                    bind&call&apply
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.10" data-path="函数.html">
            
                <a href="函数.html">
            
                    
                    函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.11" data-path="变量提升.html">
            
                <a href="变量提升.html">
            
                    
                    变量提升
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.12" data-path="作用域.html">
            
                <a href="作用域.html">
            
                    
                    作用域
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.13" data-path="对象.html">
            
                <a href="对象.html">
            
                    
                    对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.14" data-path="存储.html">
            
                <a href="存储.html">
            
                    
                    存储
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.15" data-path="事件.html">
            
                <a href="事件.html">
            
                    
                    事件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.16" data-path="图片预览.html">
            
                <a href="图片预览.html">
            
                    
                    图片预览
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.4.17" data-path="防抖节流.html">
            
                <a href="防抖节流.html">
            
                    
                    防抖节流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.18" data-path="同步异步.html">
            
                <a href="同步异步.html">
            
                    
                    同步异步
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.19" data-path="babel入门.html">
            
                <a href="babel入门.html">
            
                    
                    babel入门
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.20" data-path="nvm.html">
            
                <a href="nvm.html">
            
                    
                    nvm
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.21" data-path="ES6.html">
            
                <a href="ES6.html">
            
                    
                    ES6
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.22" data-path="ES6-ES11.html">
            
                <a href="ES6-ES11.html">
            
                    
                    ES6-ES11
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >防抖节流</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
                                <section class="normal markdown-section">
                                
                                <h2 id="&#x9632;&#x6296;">&#x9632;&#x6296;</h2>
<ul>
<li>&#x9632;&#x6296;&#x7684;&#x672C;&#x8D28;&#x5C31;&#x662F;&#x7EF4;&#x62A4;&#x4E00;&#x4E2A;&#x5B9A;&#x65F6;&#x5668;&#x7684;&#x8D85;&#x65F6;&#x65F6;&#x95F4;&#xFF0C;&#x5982;&#x679C;&#x5728;&#x8D85;&#x65F6;&#x65F6;&#x95F4;&#x5185;&#x91CD;&#x65B0;&#x89E6;&#x53D1;&#xFF0C;&#x5219;&#x6E05;&#x9664;&#x5B9A;&#x65F6;&#x5668;&#x5E76;&#x91CD;&#x65B0;&#x6CE8;&#x518C;(&#x91CD;&#x7F6E;&#x5B9A;&#x65F6;&#x5668;)</li>
</ul>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> ipt = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">&quot;.ipt&quot;</span>);
<span class="hljs-comment">// &#x521D;&#x59CB;&#x5316;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#x7528;&#x6237;&#x88C5;&#x53D6;&#x5B9A;&#x65F6;&#x5668;</span>
<span class="hljs-keyword">let</span> timer = <span class="hljs-literal">null</span>;
ipt.addEventListener(<span class="hljs-string">&quot;input&quot;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&quot;timer&quot;</span>,timer);
    <span class="hljs-comment">// &#x5982;&#x679C;timer&#x4E0D;&#x4E3A;null,&#x5219;&#x8868;&#x793A;&#x5B9A;&#x65F6;&#x4EFB;&#x52A1;&#x5DF2;&#x5B58;&#x5728;</span>
    <span class="hljs-keyword">if</span> (timer) {
        <span class="hljs-comment">// &#x6E05;&#x9664;&#x5B9A;&#x65F6;&#x4EFB;&#x52A1;&#xFF0C;&#x5E76;&#x4E14;&#x91CD;&#x65B0;&#x6CE8;&#x518C;&#x4EFB;&#x52A1;(&#x91CD;&#x7F6E;&#x5012;&#x8BA1;&#x65F6;&#x65F6;&#x95F4;)</span>
        clearInterval(timer);
    }
    <span class="hljs-comment">// &#x91CD;&#x65B0;&#x6CE8;&#x518C;&#x5B9A;&#x65F6;&#x4EFB;&#x52A1;(&#x91CD;&#x7F6E;&#x5012;&#x8BA1;&#x65F6;&#x65F6;&#x95F4;)</span>
    timer = setTimeout(() =&gt; {
        <span class="hljs-comment">// &#x6267;&#x884C;&#x4E1A;&#x52A1;&#x4EE3;&#x7801;</span>
        <span class="hljs-built_in">console</span>.log(<span class="hljs-keyword">this</span>.value);
    }, <span class="hljs-number">2000</span>)
})
</code></pre>
<h2 id="&#x8282;&#x6D41;">&#x8282;&#x6D41;</h2>
<ul>
<li>&#x901A;&#x8FC7;&#x8282;&#x6D41;&#xFF0C;&#x63A7;&#x5236;&#x51FD;&#x6570;&#x5728;&#x4E00;&#x5B9A;&#x65F6;&#x95F4;&#x5185;&#x4EC5;&#x80FD;&#x89E6;&#x53D1;&#x4E00;&#x6B21;&#xFF0C;&#x6765;&#x8FBE;&#x5230;&#x964D;&#x4F4E;&#x8C03;&#x7528;&#x9891;&#x7387;&#x7684;&#x76EE;&#x7684;&#xFF1B;</li>
<li>&#x6838;&#x5FC3;&#x601D;&#x60F3;&#xFF1A;&#x63A7;&#x5236;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;true/false&#x7684;&#x5207;&#x6362;&#x95F4;&#x9694;</li>
</ul>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> ipt = <span class="hljs-built_in">document</span>.querySelector(<span class="hljs-string">&quot;.ipt&quot;</span>);
<span class="hljs-comment">// &#x521D;&#x59CB;&#x5316;&#x4E00;&#x4E2A;&#x4F5C;&#x4E3A;&#x5F00;&#x5173;&#x7684;&#x53D8;&#x91CF;&#xFF0C;&#x7528;&#x4E8E;&#x8868;&#x793A;&#x662F;&#x5426;&#x5141;&#x8BB8;&#x6267;&#x884C;&#x51FD;&#x6570;</span>
<span class="hljs-keyword">let</span> canRun = <span class="hljs-literal">true</span>;
ipt.addEventListener(<span class="hljs-string">&quot;input&quot;</span>,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>)</span>{
    <span class="hljs-comment">// &#x5982;&#x679C;&#x4E3A;true&#x5219;&#x8868;&#x793A;&#x5141;&#x8BB8;&#x6267;&#x884C;&#xFF0C;false&#x5219;&#x4E0D;&#x5141;&#x8BB8;</span>
    <span class="hljs-keyword">if</span>(canRun){
        <span class="hljs-comment">// &#x4E00;&#x65E6;&#x51FD;&#x6570;&#x6267;&#x884C;&#xFF0C;&#x5219;&#x7ACB;&#x523B;&#x5173;&#x95ED;&#x5F00;&#x5173;&#xFF0C;&#x7B49;&#x5F85;&#x540E;&#x7EED;&#x5B9A;&#x65F6;&#x5668;&#x6253;&#x5F00;</span>
        canRun = <span class="hljs-literal">false</span>;
        <span class="hljs-comment">// &#x6267;&#x884C;&#x76F8;&#x5E94;&#x7684;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7A0B;&#x5E8F;</span>
        <span class="hljs-comment">// console.log(this.value);</span>
        <span class="hljs-keyword">let</span> url = <span class="hljs-string">`https://netease.bluej.cn/search?keywords=&#x6D77;&#x9614;&#x5929;&#x7A7A;`</span>;
        _ajax(<span class="hljs-string">&quot;get&quot;</span>,url,<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">res</span>)</span>{
            <span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">JSON</span>.parse(res));
        })
        <span class="hljs-comment">// &#x4F7F;&#x7528;&#x5B9A;&#x65F6;&#x5668;&#xFF0C;&#x63A7;&#x5236;&#x5728;&#x4E00;&#x5B9A;&#x65F6;&#x95F4;&#x540E;&#x6253;&#x5F00;canRun&#x5F00;&#x5173;</span>
        setTimeout(()=&gt;{
            canRun = <span class="hljs-literal">true</span>;
        },<span class="hljs-number">1000</span>)
    }
})
</code></pre>
<h2 id="&#x8865;&#x5145;">&#x8865;&#x5145;</h2>
<ul>
<li>console.log()&#x8F93;&#x51FA;&#x5F15;&#x7528;&#x6570;&#x636E;&#x7C7B;&#x578B;&#x65F6;&#xFF0C;&#x672A;&#x5C55;&#x5F00;&#x7684;&#x60C5;&#x6B3E;&#x4E0B;&#xFF0C;&#x4EC5;&#x8F93;&#x51FA;&#x6570;&#x636E;&#x7684;&#x72B6;&#x6001;&#x5FEB;&#x7167;&#xFF1B;&#x5F53;&#x540E;&#x7EED;&#x5C55;&#x5F00;&#x65F6;&#xFF0C;&#x4F1A;&#x91CD;&#x65B0;&#x6309;&#x7167;&#x5F15;&#x7528;&#x5730;&#x5740;&#x5BFB;&#x627E;&#x5185;&#x5B58;&#x91CC;&#x9762;&#x7684;&#x53D8;&#x91CF;&#xFF0C;&#x8F93;&#x51FA;&#x6700;&#x65B0;&#x7684;&#x6570;&#x636E;&#x72B6;&#x6001;</li>
</ul>
<pre><code class="lang-js"><span class="hljs-keyword">let</span> obj ={
    age: <span class="hljs-number">18</span>,
    name: <span class="hljs-string">&quot;bluej&quot;</span>
};
<span class="hljs-built_in">console</span>.log(obj);
obj.age = <span class="hljs-number">22</span>;
</code></pre>

                                
                                </section>
                            
                        </div>
                    </div>
                
            </div>

            
                
                <a href="图片预览.html" class="navigation navigation-prev " aria-label="Previous page: 图片预览">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="同步异步.html" class="navigation navigation-next " aria-label="Next page: 同步异步">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"防抖节流","level":"1.4.17","depth":2,"next":{"title":"同步异步","level":"1.4.18","depth":2,"path":"md/03js/同步异步.md","ref":"./md/03js/同步异步.md","articles":[]},"previous":{"title":"图片预览","level":"1.4.16","depth":2,"path":"md/03js/图片预览.md","ref":"./md/03js/图片预览.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-search","-sharing","toggle-chapters","image-captions","-anchor-navigation","-anchor-navigation-ex"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"image-captions":{"attributes":{"style":"left: 50%;position: relative;transform: translateX(-50%);"},"caption":"图 _PAGE_LEVEL_._PAGE_IMAGE_NUMBER_ - _CAPTION_","align":"center","variable_name":"_pictures"},"fontsettings":{"theme":"night","family":"sans","size":2},"toggle-chapters":{},"highlight":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"Landen","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{"_pictures":[]},"gitbook":"3.x.x"},"file":{"path":"md/03js/防抖节流.md","mtime":"2020-08-09T05:18:32.266Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-08-17T10:41:18.504Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-toggle-chapters/toggle.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

